# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: DCPDialog.py
  @time: 2022/4/13 16:32
  @desc:
"""
import sys
from PyQt5.QtCore import QSize, Qt, QRect, pyqtSignal
from PyQt5.QtGui import QIcon, QBrush, QColor, QPen, QFont, QPainter
from PyQt5.QtWidgets import QApplication, QWidget, QDialog, QVBoxLayout, QGridLayout, QComboBox, QPushButton, QLabel, \
    QMessageBox, QLineEdit
from gui import constant


class ManualDialog(QDialog):
    send_signal = pyqtSignal(object)

    def __init__(self, parent=None):
        super().__init__(parent)
        # with open("./static/style_sheet/origin.qss", mode='r', encoding='utf-8') as f:
        #     style_sheet = f.read()
        # self.setStyleSheet(style_sheet)
        self.setWindowTitle("Manual")
        self.setWindowIcon(QIcon("./static/style_sheet/icons/logo.png"))
        self.resize(300, 200)
        self.vl_dcp = QVBoxLayout(self)
        self.vl_dcp.setContentsMargins(0, 0, 0, 0)
        self.wd_dcp = QWidget()
        self.gl_dcp = QGridLayout(self.wd_dcp)
        self.l_diex = QLabel("DieX")
        self.le_diex = QLineEdit()
        self.l_diey = QLabel("DieY")
        self.le_diey = QLineEdit()
        self.l_subdie_name = QLabel("SubDie_Name")
        self.le_subdie_name = QLineEdit()
        self.pb_submit = QPushButton("提交")
        self.gl_dcp.addWidget(self.l_diex, 0, 0)
        self.gl_dcp.addWidget(self.le_diex, 0, 1)
        self.gl_dcp.addWidget(self.l_diey, 1, 0)
        self.gl_dcp.addWidget(self.le_diey, 1, 1)

        self.gl_dcp.addWidget(self.l_subdie_name, 2, 0)
        self.gl_dcp.addWidget(self.le_subdie_name, 2, 1)

        self.gl_dcp.addWidget(self.pb_submit, 3, 0, 1, 2)
        self.vl_dcp.addWidget(self.wd_dcp)
        self.vl_dcp.addStretch(1)
        self.pb_submit.clicked.connect(self.send_content)

    def send_content(self):
        diex = self.le_diex.text()
        diey = self.le_diey.text()
        subdie_name = self.le_subdie_name.text()
        if not all([diex, diey, subdie_name]):
            self.show_critical("警告", "die和subdie不能为空")
        else:
            self.close()
            self.send_signal.emit([diex, diey, subdie_name])

    def is_none(self, value):
        return True if value.strip() != "None" else False

    def show_critical(self, title, content):
        QMessageBox.critical(self, title, content)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = ManualDialog()
    window.show()
    sys.exit(app.exec())
